#define _CRT_SECURE_NO_WARNINGS 1

#include "Data.h"

Data::Data(int year, int month, int day)
{
	_year = year;
	_month = month;
	_day = day;
}

Data::Data(const Data& d)
{
	_year = d._year;
	_month = d._month;
	_day = d._day;
}

Data& Data::operator=(const Data& d)
{
	_year = d._year;
	_month = d._month;
	_day = d._day;
	return *this;
}

bool Data::operator>(Data& d)
{
	if (_year > d._year)
	{
		return true;
	}
	else if (_year == d._year && _month > d._month)
	{
		return true;
	}
	else if (_year == d._year && _month == d._month && _day > d._day)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool Data::operator==(Data& d)
{
	return _year == d._year
		&& _month == d._month
		&& _day == d._day;
}

bool Data::operator>=(Data& d)
{
	return (*this > d) || (*this == d);
}

bool Data::operator<(Data& d)
{
	return !(*this >= d);
}

bool Data::operator<=(Data& d)
{
	return !(*this > d);
}
bool Data::operator!=(Data& d)
{
	return !(*this == d);
}


int Data::MonthDays(int year, int month)
{
	int MonthArr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	if (month == 2 && ((year % 4 == 0 && year % 100 != 0) && (year % 400 == 0)))
	{
		return 29;
	}

	return MonthArr[month];
}

Data& Data::operator+=(int day)
{
	_day += day;

	while (_day > MonthDays(_year, _month))
	{
		_day -= MonthDays(_year, _month);
		_month++;

		if (_month >  12)
		{
			_year++;
			_month = 1;
		}
	}

	//*this = *this + day;

	return *this;
}

Data Data::operator+(int day)
{
	Data tmp = *this;
	tmp._day += day;

	while (tmp._day > tmp.MonthDays(tmp._year, tmp._month))
	{
		tmp._day -= tmp.MonthDays(tmp._year, tmp._month);
		tmp._month++;

		if (tmp._month > 12)
		{
			tmp._year++;
			tmp._month = 1;
		}
	}

	//tmp += day;

	return tmp;
}




